<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Project;

/**
 * ProjectSearch represents the model behind the search form about `app\models\Project`.
 */
class ProjectSearch extends Project
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'userid', 'isfinish', 'updatetime', 'addmanid', 'addtime'], 'integer'],
            [['projectno', 'projectname', 'chargeman', 'unit', 'projectfrom', 'zhxtype', 'projectlevel', 'projectplantype', 'discipline', 'status', 'projectmember', 'addman', 'member', 'projectmoney', 'mark'], 'safe'],
            [['jf_dxjf', 'jf_zzjf', 'jf_jhnhx', 'jf_jhwhx', 'jf_sbgzf', 'jf_zcjf', 'jf_ppf', 'jf_zcjfhj', 'jf_syjf'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Project::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            //分页
            'pagination' => [
                'pageSize' => 10,
            ],
            //排序
            'sort'=>[
                'defaultOrder'=>[
                    'id'=>SORT_ASC,
                ]
            ]
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'userid' => $this->userid,
            'isfinish' => $this->isfinish,
            'updatetime' => $this->updatetime,
            'addmanid' => $this->addmanid,
            'addtime' => $this->addtime,
            'jf_dxjf' => $this->jf_dxjf,
            'jf_zzjf' => $this->jf_zzjf,
            'jf_jhnhx' => $this->jf_jhnhx,
            'jf_jhwhx' => $this->jf_jhwhx,
            'jf_sbgzf' => $this->jf_sbgzf,
            'jf_zcjf' => $this->jf_zcjf,
            'jf_ppf' => $this->jf_ppf,
            'jf_zcjfhj' => $this->jf_zcjfhj,
            'jf_syjf' => $this->jf_syjf,
        ]);

        $query->andFilterWhere(['like', 'projectno', $this->projectno])
            ->andFilterWhere(['like', 'projectname', $this->projectname])
            ->andFilterWhere(['like', 'chargeman', $this->chargeman])
            ->andFilterWhere(['like', 'unit', $this->unit])
            ->andFilterWhere(['like', 'projectfrom', $this->projectfrom])
            ->andFilterWhere(['like', 'zhxtype', $this->zhxtype])
            ->andFilterWhere(['like', 'projectlevel', $this->projectlevel])
            ->andFilterWhere(['like', 'projectplantype', $this->projectplantype])
            ->andFilterWhere(['like', 'discipline', $this->discipline])
            ->andFilterWhere(['like', 'status', $this->status])
            ->andFilterWhere(['like', 'projectmember', $this->projectmember])
            ->andFilterWhere(['like', 'addman', $this->addman])
            ->andFilterWhere(['like', 'member', $this->member])
            ->andFilterWhere(['like', 'projectmoney', $this->projectmoney])
            ->andFilterWhere(['like', 'mark', $this->mark]);

        return $dataProvider;
    }
}
